<!--人资管理-人员调配审批记录列表-->
<template>
  <PageTemplate>
    <div class="plan-list" slot="content">
      <el-form
        inline
        :model="query"
        ref="query"
        label-position="right"
        label-width="110px"
        class="search-collapse-pro-form"
      >
        <SearchCollapsePro :isAdvSearch="false">
          <div slot="title" class="search-collapse-pro-title">
            <el-form-item label-width="0px">
              <el-input v-model="query.searchKey" placeholder="发起人">
                <el-button slot="append" icon="el-icon-search" @click="queryDataTableLike"></el-button>
              </el-input>
            </el-form-item>
          </div>
        </SearchCollapsePro>
      </el-form>
      <el-row class="row-empty-20"></el-row>
      <PageTableCollapse :collapseStatus="true">
        <el-row slot="title">
          <el-col>
            <div>
              <el-button v-if="showBtn" icon="el-icon-download" type="primary" @click="exportHandle">
                 导出
              </el-button>
            </div>
          </el-col>
        </el-row>
        <el-table
          class="table"
          border
          ref="multipleTable"
          :data="tables"
          tooltip-effect="dark"
          style="width: 100%"
          :show-overflow-tooltip="true"
          @selection-change="handleSelectionChange"
          :header-cell-style="{background:tableHeaderBGC}"
        >
          <!-- <el-table-column align="center" type="selection" width="60"></el-table-column> -->
          <el-table-column type="index" :index="indexMethod" :label="$t('cm.no')" align="center" width="60" fixed></el-table-column>
          <el-table-column prop="processName" label="流程类型" align="center"></el-table-column>
          <el-table-column prop="folio" label="流程主题" align="center"></el-table-column>
           <el-table-column
            prop="status" label="状态" align="center"
              :formatter="(row)=>{
              let result = '';
              switch (row.status-0) {
                case 0:
                  result = '进行中';
                  break;
                case 1:
                  result = '已完成';
                  break;
              }
              return result;
           }"></el-table-column>
          <el-table-column prop="currentAct" label="当前环节" align="center"></el-table-column>
          <el-table-column prop="currentDealName" label="当前审批人" align="center"></el-table-column>
          <el-table-column prop="startUserName" label="发起人" align="center"></el-table-column>
          <el-table-column prop="startTime" label="发起日期" :formatter="dateFormat" align="center"></el-table-column>
        </el-table>
        <div class="block pager-customer">
          <el-pagination
            background
            layout="total,prev,pager, next,jumper"
            :current-page.sync="pagingCurrentPageNum"
            :page-sizes="pagingPageSizes"
            :page-size="pagingPageSize"
            :total="pagingTotal"
            @size-change="pagingHandleSizeChange"
            @current-change="pagingHandleCurrentChange"
          >
          </el-pagination>
        </div>
      </PageTableCollapse>
    </div>
  </PageTemplate>
</template>

<script>
import { mapState, mapActions } from 'vuex'
import PageTemplate from '@/components/common/PageTemplate'
import PageTableCollapse from '@/components/common/PageTableCollapse'
import SearchCollapsePro from '@/components/common/SearchCollapsePro'
import ListBtn from '@/components/btn/ListBtn'
import { ALERT } from '@/utils/responseHandle'
import * as Constant from '@/utils/constant'
import {COMMON} from '@/utils/commonUtil'
import Pagination from '@/mixins/Pagination'
import HasBtn from '@/mixins/HasBtn'
import api_hr from '@/api/api_hr'
import sys_manage from '@/api/sys_manage'
import {dateFtt} from '@/utils/datetime'

export default {
  components: {
    PageTemplate,
    PageTableCollapse,
    SearchCollapsePro,
    ListBtn
  },
  data () {
    return {
      query: {
        searchKey:null
      },
      tables:[],
      btns: [
      {
        value: 'look',
        label: 'cm.look'
      },
      {
        value: 'alter',
        label: 'cm.alter'
      },
      {
        value: 'progress',
        label: 'cm.progress'
      },
      {
        value: 'close',
        label: 'cm.close'
      }
    ],
    indexTypeMap:[],//索引类别字典
    }
  },
  created () {
    //获取全部字典
    this.getAllMap();
    this.getAllDataTable();
  },
  mixins: [Pagination, HasBtn],
  computed: {
    ...mapState({
      tableHeaderBGC: state => state.common.tableHeaderBGC
    })
  },
  methods:{
    dateFormat(thistime, fmt) {
      //console.log("-125Sysdist-",thistime);
      //console.log("-126Sysdist-",fmt);
      //console.log("-127Sysdist-",thistime.lastUpdateTime);
      if (!COMMON.isNullOrUndefinedOrSpace(thistime.lastUpdateTime)) {
            var date = new Date(thistime.lastUpdateTime)
            var month =date.getMonth()+1;if(month<10){month="0"+month;}
            var day =date.getDate();if(day<10){day="0"+day;}
            var hours =date.getHours();if(hours<10){hours="0"+hours;}
            var min= date.getMinutes();if(min<10){ min="0"+min; }
            var sec= date.getSeconds();if(sec<10){sec="0"+sec;}
          return  date.getFullYear() + '-' + month + '-' + day + ' ' + hours + ':' +min+':'+sec
      }
          return thistime.lastUpdateTime
    },
     //获取全部字典
    getAllMap(){
       //索引类别字典
      this.sysDictLoadByPaging("achievement_index_type",(result)=>{
          this.indexTypeMap = result.data
      })
    },
    //获取字典接口
    sysDictLoadByPaging (key,callback) {
      sys_manage.sysDictLoadByPaging({dictGroupKey: key}, result => {
        if (result.code === Constant.RT_SUCCESS) {
          callback(result)
        } else {
          ALERT.error(result.msg)
        }
      })
    },
    //重置操作
    queryReset (formName) {
      this.$refs[formName].resetFields()
    },

    // 导出
    exportHandle () {
       let params = Object.assign({},this.query,{
        pageNum:this.pagingCurrentPageNum,
        pageSize:this.pagingPageSize
      })
      let fileName = `调试人资管理_审批流程列表_${dateFtt('yyyy-MM-dd', new Date())}`
      api_hr.hrProcessRecordExportExcel(params, response => {
        if (response.code === Constant.RT_SUCCESS) {
          COMMON.downloadLinkByUrl(response.data.webRequestUrl, fileName)
        } else {
          ALERT.alertResp(response)
        }
      })
    },
    queryDataTableLike () {
      this.getAllDataTable();
    },
     getAllDataTable () {
      this.queryTableList({
        ...this.query,
        pageNum: this.pagingCurrentPageNum,
        pageSize: this.pagingPageSize
      })
    },
    //统一与后台操作的方法
    queryTableList (params) {
      //这里的params是对象
      //注意 如果后台json转对象 时间类型好像会抛异常  转到后台 前台用 qs 来转换数据 设置一个全局拦截器 main.js 参考
      let _this = this
      let tables = []
      let totalCount = 0
      api_hr.hrProcessRecordListPage(params, result => {
        if (result.code === Constant.RT_SUCCESS) {
          //表格数据  数组
          tables = result.data.results
          //分页数据
          totalCount = result.data.totalRows
        } else {
          // _this.$t('cm.tips')
          ALERT.error(result.data.msg)
        }
        _this.setPagingTotal(totalCount)
        this.tables = tables
      })
    },
  }
}

</script>

<style lang="scss">

</style>
